<?php
    $conn = new mysqli('localhost', 'root', 'root', 'sanxing');

    if ($conn -> connect_error) {
        die('登录失败');
    }

    // 接收前端的参数
    $username = $_POST['username'];
    $password = $_POST['password'];

    $sql = "SELECT * FROM `user_data` WHERE `username`='$username' AND `password`='$password'";

    $res = $conn -> query($sql);

    $arr = array();

    $row = mysqli_fetch_assoc($res);

    if ($row) {
        echo json_encode(array(
            'state' => true,
            'msg' => '登录成功'
        ));
    } else {
        echo json_encode(array(
            'state' => false,
            'msg' => '登录失败'
        ));
    }
?>